from django import template 
 from util import parse_args_kwargs_and_as_var
 from django.template import Context
 from django.template.loader import render_to_string
 
 register = template.Library()
 
 @register.tag(name="runquery")
 def do__run_query(parser, token):
     args, kwargs, as_var = parse_args_kwargs_and_as_var(parser, token.split_contents()[1:])
     parser.delete_first_token()
     return RunQueryNode(args, kwargs, as_var)
 
 class RunQueryNode(template.Node):
     def __init__(self, args, kwargs, as_var):
         self.as_var = as_var
         self.name = kwargs.get('name').token
         self.evalto = kwargs.get('eval_to', None)
         self.queryargs = kwargs.get('query_args', None)
         
     def render(self, context):
         context['eval_to'] = self.evalto
         context['as'] = self.as_var
         return render_to_string('%s.html'%self.name, context)